package vip.xumy.admin.bmap.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import vip.xumy.admin.bmap.pojo.DownWorker;
import vip.xumy.admin.bmap.pojo.WorkContext;

/**
 * @author:mengyxu
 * @date:2021年10月26日
 */

@Mapper
public interface ILoadWorkMapper {
	static final String INSERT_COLUMN = "city, city_name, add_time, status, min_zom, max_zom, total";

	@Select({ "<script>", "SELECT * FROM bmap_load_work ", "<where>",
			"<if test='cityName != null'> AND city_name like CONCAT('%',#{cityName},'%') </if>",
			"<if test='id != null'> AND id = #{id} </if>", "<if test='city != null'> AND city = #{city} </if>",
			"<if test='status != null'> AND status = #{status} </if>", "</where>", "ORDER BY add_time DESC",
			"</script>" })
	List<DownWorker> list(DownWorker example);

	@Insert({ "<script>", "INSERT INTO bmap_load_work ( ", INSERT_COLUMN, " ) VALUES ",
			"<foreach collection='list' item='item' separator=','>",
			"(#{item.city}, #{item.cityName}, NOW(), 0, #{item.minZom}, #{item.maxZom}, #{item.total}) ", "</foreach>",
			"</script>" })
	@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
	void saveBatch(List<WorkContext> context);

	@Insert({ "<script>", "INSERT INTO bmap_load_work ( ", INSERT_COLUMN, " ) VALUES ",
			"(#{city}, #{cityName}, NOW(), 0, #{minZom}, #{maxZom}, #{total}) ", "</script>" })
	@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
	void save(WorkContext context);

	@Update({ "UPDATE bmap_load_work SET start_time = #{startTime}, end_time = #{endTime}, status = #{status}, ",
			"`exist` = #{exist}, success = #{success}, fail = #{fail}, result = #{result} WHERE id = #{id}" })
	void update(DownWorker context);

}
